package com.decent.sms.configs;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.endpoint.DefaultEndpointResolver;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 阿里滑块验证码配置信息
 *
 * @author wangyx
 */
@Configuration
@PropertySource(value = "classpath:i-acs-config.properties")
@Getter
@Component
public class IAcsConfig {
    /**
     * 阿里云账号id
     */
    @Value("${acs_access_key_id}")
    private String accessKeyId;
    /**
     * 阿里云账号密钥
     */
    @Value("${acs_access_key_secret}")
    private String accessKeySecret;
    /**
     * 滑动验证码key
     */
    @Value("${acs_app_key}")
    private String appKey;
    /**
     * 阿里云OSS客户端
     */
    private IAcsClient iAcsClient;

    @PostConstruct
    public void initClient() {
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        iAcsClient = new DefaultAcsClient(profile);
        DefaultEndpointResolver.predefinedEndpointResolver.putEndpointEntry("cn-hangzhou", "afs", "cn-hangzhou");
    }
}
